<template>
  <el-container>
    <el-header style="padding: 0; height: 100%">
      <div class="searchBox">
        <el-input
          v-model="listquery.key"
          size="small"
          suffix-icon="el-icon-search"
          class="einput"
        />
        <div class="daoButton" @click="download">
          <img src="@/assets/daochu.png" alt="" />
          <span>全部导出</span>
        </div>
      </div>
    </el-header>
    <el-main>
      <el-table
        :data="tableData"
        stripe
        border
        style="width: 100%"
        class="eltable"
      >
        <el-table-column label="序号" width="100" type="index" />
        <el-table-column prop="userName" label="单位名称" width="180" />
        <el-table-column prop="contactName" label="联系人" />
        <el-table-column prop="contactPhone" label="联系方式 " />
        <el-table-column prop="qualificationLevel" label="编制资质 ">
          <template scope="scope">
            <span
              v-if="scope.row.qualificationLevel === '1'"
              style="color: green"
              >甲级</span
            >
            <span v-else style="color: gray">乙级</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template scope="scope">
            <span v-if="scope.row.status == '1'" style="color: green"
              >已通过</span
            >
            <span v-else style="color: red">已拒绝</span>
          </template>
        </el-table-column>
      </el-table>
      <right-panel
        :obj="objv"
        v-if="rightPanelShow"
        @closeRightPanel="closeRightPane"
      ></right-panel>

      <el-pagination
        v-if="tableData.length > 0"
        class="elpagi"
        :total="total"
        @size-change="getdata"
        @current-change="getdata"
        @prev-click="getdata"
        @next-click="getdata"
        :current-page.sync="listquery.currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="listquery.pageSize"
        layout="total,sizes, prev, pager, next, jumper"
      />
      <!-- :tableData="result.slice((curPage - 1) * pageSize, curPage * pageSize)" -->
    </el-main>
  </el-container>
</template>
<script>
import tableHeader from "../components/TableHeader";
import rightPanel from "../components/rightPanel";
import { getdolist } from "@/api/shenhe.js";
import { export_json_to_excel } from "@/utils/export2Excel.js";
export default {
  components: {
    tableHeader,
    rightPanel,
  },
  data() {
    return {
      isShow: false,
      objv: null,
      listquery: {
        pageSize: 10,
        currentPage: 1,
        key: "",
      },
      tableData: [],
      rightPanelShow: false,
    };
  },
  mounted() {
    this.getdata();
  },
  methods: {
    download() {
      let query = {
        pageSize: 99999,
        currentPage: 1,
        key: this.listquery.key,
      };
      getdolist(query).then((res) => {
        let tablelist = res.data.content;
        this.downloadExcel(tablelist);
      });
    },
    downloadExcel(tabledatalist) {
      let header = Object.keys(tabledatalist[0]);
      let list2 = [];
      for (var i = 0; i < tabledatalist.length; i++) {
        let list1 = [];
        for (var j = 0; j < header.length; j++) {
          let obj = tabledatalist[i];
          list1.push(obj[header[j]]);
        }
        list2.push(list1);
      }
      export_json_to_excel({
        header: header,
        data: list2,
        filename: "单位审核已办表",
      });
    },
    async getdata() {
      this.isloading = true;
      let res = await getdolist(this.listquery);
      this.tableData = res.data.content;
      this.total = res.data.totalElements;
      this.isloading = false;
    },
    query(scope) {
      this.rightPanelShow = true;
      this.objv = scope.row;
    },
    closeRightPane() {
      this.rightPanelShow = false;
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../../../public/css/table.scss";
.red {
  background-color: #4778c7;
}
.gray {
  background-color: #cdc5bf;
}
.green {
  background-color: #3cb371;
}
</style>
